package org.gov.vis.gui;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import org.gov.vis.data.gui.AIDialog;
import org.gov.vis.data.gui.AddProgencyDialog;
import org.gov.vis.data.gui.DistributionLNDialog;
import org.gov.vis.data.gui.DistributionSemenDialog;
import org.gov.vis.data.gui.ProcurementLNDialog;
import org.gov.vis.data.gui.ProcurementSemenDialog;
import org.gov.vis.data.gui.ViewAIDialog;
import org.gov.vis.data.gui.ViewDistributionLNDialog;
import org.gov.vis.data.gui.ViewDistributionSemenDialog;
import org.gov.vis.data.gui.ViewProcurementLNDialog;
import org.gov.vis.data.gui.ViewProcurementSemenDialog;
import org.gov.vis.data.gui.ViewProgencyDialog;
import org.gov.vis.main.Main;
import org.gov.vis.master.gui.AddGopalMithraDialog;
import org.gov.vis.master.gui.DepartmentDialog;
import org.gov.vis.master.gui.OthersDialog;
import org.gov.vis.master.gui.StaffDialog;
import org.gov.vis.master.gui.ViewDepartmentDialog;
import org.gov.vis.master.gui.ViewGopalaMithraDialog;
import org.gov.vis.master.gui.ViewOthersDialog;
import org.gov.vis.master.gui.ViewStaffDialog;
import org.gov.vis.util.Util;

public class VisJFrame extends JFrame{

	private static final long serialVersionUID = 8978922365346953367L;
	private ResourceBundle resources=Util.getResources();
	
	
	public VisJFrame(String title){
		super(title);
		
		JMenuBar menubar=new JMenuBar();
		
		JMenu adminMenu=createMasterMenu();		
		menubar.add(adminMenu);	
		
		JMenu dataMenu = createDataMenu();
		menubar.add(dataMenu);
		
		setJMenuBar(menubar);
		
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		setBounds(0,0,(screenSize.width-50),(screenSize.height-50));
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		JDesktopPane desktop = new JDesktopPane();
		setContentPane(desktop);		
		setVisible(true);
	}
	
	/**
	 * Returns MasterMenu
	 * @return master menu
	 */
	private JMenu createMasterMenu(){
		JMenu masterMenu=new JMenu(resources.getString("jframe.menubar.menu.master"));
		
		JMenu deptMenu=new JMenu(resources.getString("jframe.menubar.menu.dept"));
		JMenuItem addeptMI=new JMenuItem(resources.getString("menubar.menu.addDept"));
		addeptMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new DepartmentDialog(Main.getMainFrame(),
                        resources.getString("dialog_addDept_title"),
                        false);
			}
		});
		deptMenu.add(addeptMI);
		
		// View Others Menu Item
		JMenuItem viewDepartmentMI=new JMenuItem("View Department");
		viewDepartmentMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ViewDepartmentDialog(Main.getMainFrame(),
                        "View Department",
                        false);
			}
		});
		deptMenu.add(viewDepartmentMI);
		
		
		masterMenu.add(deptMenu);
		
		
		//GopalaMithra Menu
		JMenu gopalaMithraMenu=new JMenu(resources.getString("jframe.menubar.menu.gopalmithra"));
		masterMenu.add(gopalaMithraMenu);
		
		// Add GopalaMithra Menu Item
		JMenuItem gopalaMithraMI=new JMenuItem(resources.getString("menubar.menu.add.gopalamithra"));
		gopalaMithraMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new AddGopalMithraDialog(Main.getMainFrame(),
                        resources.getString("dialog_add_gopalamithra_title"),
                        false);
			}
		});
		gopalaMithraMenu.add(gopalaMithraMI);
		
		// View GopalaMithra Menu Item
		JMenuItem viewGopalaMithraMI=new JMenuItem(resources.getString("menubar.menu.edit.gopalamithra"));
		viewGopalaMithraMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ViewGopalaMithraDialog(Main.getMainFrame(),
                        resources.getString("dialog_view_gopalamithra_title"),
                        false);
			}
		});
		gopalaMithraMenu.add(viewGopalaMithraMI);

		
		JMenu othersMenu=new JMenu("Others");
		masterMenu.add(othersMenu);
		// View GopalaMithra Menu Item
		JMenuItem addOthersMI=new JMenuItem("Add Others");
		addOthersMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new OthersDialog(Main.getMainFrame(),
                        "Add Others",
                        false);
			}
		});
		othersMenu.add(addOthersMI);
		
		// View Others Menu Item
		JMenuItem viewOthersMI=new JMenuItem("View Others");
		viewOthersMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ViewOthersDialog(Main.getMainFrame(),
                        "View Others",
                        false);
			}
		});
		othersMenu.add(viewOthersMI);
		
		JMenu staffMenu=new JMenu("Staff");
		masterMenu.add(staffMenu);
		// View GopalaMithra Menu Item
		JMenuItem addStaffMI=new JMenuItem("Add Staff");
		addStaffMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new StaffDialog(Main.getMainFrame(),
                        "Add Staff",
                        false);
			}
		});
		staffMenu.add(addStaffMI);
		
		// View Others Menu Item
		JMenuItem viewStaffMI=new JMenuItem("View Staff");
		viewStaffMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ViewStaffDialog(Main.getMainFrame(),
                        "View Staff",
                        false);
			}
		});
		staffMenu.add(viewStaffMI);
		
		return masterMenu;
	}
	
	private JMenu createDataMenu(){
		JMenu dataMenu=new JMenu("Data");
		JMenu aiMenu=new JMenu("AI");
		dataMenu.add(aiMenu);
		// View GopalaMithra Menu Item
		JMenuItem addAIMenuItem=new JMenuItem("Add AI");
		addAIMenuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new AIDialog(Main.getMainFrame(),
                        "Add AI",
                        false);
			}
		});
		aiMenu.add(addAIMenuItem);
		
		JMenuItem vewAIMenuItem=new JMenuItem("View AI");
		vewAIMenuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ViewAIDialog(Main.getMainFrame(),
                        "View AI",
                        false);
			}
		});
		aiMenu.add(vewAIMenuItem);
		
		JMenu progencyMenu=new JMenu("Progency");
		dataMenu.add(progencyMenu);
		// View GopalaMithra Menu Item
		JMenuItem addPrgyMenuItem=new JMenuItem("Add Progency");
		addPrgyMenuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new AddProgencyDialog(Main.getMainFrame(),
                        "Add Progency",
                        false);
			}
		});
		progencyMenu.add(addPrgyMenuItem);

		// View GopalaMithra Menu Item
		JMenuItem viewPrgyMenuItem=new JMenuItem("View Progency");
		viewPrgyMenuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ViewProgencyDialog(Main.getMainFrame(),
                        "View Progency",
                        false);
			}
		});
		progencyMenu.add(viewPrgyMenuItem);
		
		JMenu procurumentMenu=new JMenu("Procurement");
		dataMenu.add(procurumentMenu);
		// View GopalaMithra Menu Item
		JMenu pSemenMenuItem=new JMenu("Semen");
		procurumentMenu.add(pSemenMenuItem);
		JMenuItem addSemenSubMI=new JMenuItem("Add Semen");
		addSemenSubMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ProcurementSemenDialog(Main.getMainFrame(),
                        "Add Semen",
                        false);
			}
		});
		pSemenMenuItem.add(addSemenSubMI);
		
		JMenuItem viewSemenSubMI=new JMenuItem("View Semen");
		viewSemenSubMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ViewProcurementSemenDialog(Main.getMainFrame(),
                        "View Semen",
                        false);
			}
		});
		pSemenMenuItem.add(viewSemenSubMI);
		
		
		JMenu pLNMenuItem=new JMenu("LN");
		procurumentMenu.add(pLNMenuItem);
		JMenuItem addLNSubMI=new JMenuItem("Add LN");
		addLNSubMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ProcurementLNDialog(Main.getMainFrame(),
                        "Add LN",
                        false);
			}
		});
		pLNMenuItem.add(addLNSubMI);
		
		JMenuItem ViewLNSubMI=new JMenuItem("View LN");
		ViewLNSubMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ViewProcurementLNDialog(Main.getMainFrame(),
                        "Add LN",
                        false);
			}
		});
		pLNMenuItem.add(ViewLNSubMI);
		
		dataMenu.add(procurumentMenu);

		JMenu distributionMenu=new JMenu("Distribution");
		dataMenu.add(distributionMenu);
		// View GopalaMithra Menu Item
		JMenu dSemenMenuItem=new JMenu("Semen");
		distributionMenu.add(dSemenMenuItem);
		JMenuItem addDSemenSubMI=new JMenuItem("Add Semen");
		addDSemenSubMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new DistributionSemenDialog(Main.getMainFrame(),
                        "Add Semen",
                        false);
			}
		});
		dSemenMenuItem.add(addDSemenSubMI);
		
		//View DistributionLN Menu
		JMenuItem viewDSemenSubMI=new JMenuItem("View Semen");
		viewDSemenSubMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ViewDistributionSemenDialog(Main.getMainFrame(),
                        "View Semen",
                        false);
			}
		});
		dSemenMenuItem.add(viewDSemenSubMI);


		
		JMenu dLNMenuItem=new JMenu("LN");
		distributionMenu.add(dLNMenuItem);
		
		//Add DistributionLN 
		JMenuItem addDLNSubMI=new JMenuItem("Add LN");
		addDLNSubMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new DistributionLNDialog(Main.getMainFrame(),
                        "Add LN",
                        false);
			}
		});
		dLNMenuItem.add(addDLNSubMI);
		
		//View DistributionLN Menu
		JMenuItem viewDLNSubMI=new JMenuItem("View LN");
		viewDLNSubMI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent event){
				new ViewDistributionLNDialog(Main.getMainFrame(),
                        "View LN",
                        false);
			}
		});
		dLNMenuItem.add(viewDLNSubMI);

		dataMenu.add(distributionMenu);

				return dataMenu;
	}//end createDataMenu
	
}
